<template>
  <div class="container">
    <div class="left">
      <div class="box">
        <div class="title">
          <div class="title_nav">
            <div class="title_button" @click="toIndex">
              <div class="title_img"></div>
              <span>首页</span>
            </div>
            <span>/</span>
            <span>正文</span>
          </div>
          <div class="title_content">
            <h1>{{ tableData.title }}</h1>
          </div>
        </div>
        <div class="info">
          <img src="@/assets/icon/time.png" alt="" />
          <span>发表于</span><span>{{ tableData.updateTime }}</span>
          <img src="@/assets/icon/wenjian.png" alt="" />
          <span>分类于</span>
          <span @click="toIncludeType()">{{ tableData.categoryName }}</span>
          <img src="@/assets/icon/eye.png" alt="" />
          <span>阅读量</span>
          <span>{{ tableData.readNum }}</span>
        </div>
        <div class="content" v-html="tableData.content"></div>
        <div class="tag">
          <span
            v-for="(item, index) in tableData.tags"
            :key="index"
            @click="toIncludeTag(item)"
          >
            #{{ item.name }}</span
          >
        </div>
        <div class="updown">
          <div
            class="updown_left"
            @click="upData()"
            v-if="tableData.preArticle"
          >
            <p>{{ "<" }}上一篇</p>
            <p>{{ tableData.preArticle.title }}</p>
          </div>
          <div
            class="updown_right"
            @click="downData()"
            v-if="tableData.nextArticle"
          >
            <p>下一篇{{ ">" }}</p>
            <p>{{ tableData.nextArticle.title }}</p>
          </div>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="right_1">
        <Ha-com></Ha-com>
      </div>
      <div class="right_2">
        <Type-com></Type-com>
      </div>
      <div class="right_3">
        <Tag-com></Tag-com>
      </div>
    </div>
  </div>
</template>

<script>
import HaCom from "@/components/HaCom.vue";
import TagCom from "@/components/TagCom.vue";
import TypeCom from "@/components/TypeCom.vue";

// import PageCom from "@/components/PageCom.vue";
export default {
  data() {
    return {
      categoryId: "", //要传的标签id
      categoryName: "", //要传的标签内容
      titleImgSrc: "",
      tableData: "",
      //当前页
      currentInd: 1,
      //传递的参数
      pageSize: 10,
      pageNumber: null,
      pages: [],
    };
  },
  components: {
    HaCom,
    TypeCom,
    TagCom,
    // PageCom,
  },
  methods: {
    toIndex() {
      // this.$router.push("/home/index")
    },
    upData() {
      this.$axios
        .post("api/article/detail", {
          articleId: this.tableData.preArticle.id,
        })
        .then((res) => {
          // console.log(res);
          this.tableData = res.data;
          this.categoryId = res.data.categoryId;
          this.categoryName = res.data.categoryName;
        });
    },
    downData() {
      this.$axios
        .post("api/article/detail", {
          articleId: this.tableData.nextArticle.id,
        })
        .then((res) => {
          // console.log(res);
          this.tableData = res.data;
          this.categoryId = res.data.categoryId;
          this.categoryName = res.data.categoryName;
        });
    },
    toIncludeTag(item) {
      this.$router.push({
        path: "/home/includetag",
        query: item,
      });
    },
    toDetail(item) {
      this.$router.push({
        path: "/home/detail",
        query: item,
      });
    },
    toIncludeType() {
      this.$router.push(
        {
          path: "/home/includetype",
          query: {
            id: this.categoryId,
            name: this.categoryName,
          },
        },
        () => {},
        () => {}
      );
    },
    getData() {
      this.$axios
        .post("api/article/detail", {
          articleId: this.$route.query.id,
        })
        .then((res) => {
          console.log(res);
          this.tableData = res.data;
          this.categoryId = res.data.categoryId;
          this.categoryName = res.data.categoryName;
          console.log(this.tableData, "tabledata");
        });
    },
  },
  created() {
    this.getData();
    // console.log(this.$route.query)
  },
};
</script>

<style lang="scss" scoped>
.container {
  display: flex;
  justify-content: space-around;
  .left {
    width: 960px;

    .box {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      background-color: #fff;
      padding: 20px;

      > div {
        margin-bottom: 10px;
      }
      .title {
        text-align: left;
        .title_nav {
          display: flex;
          flex-direction: row;
          .title_button {
            display: flex;
            flex-direction: row;
            .title_img {
              width: 29px;
              height: 20px;
              background-image: url("../assets/icon/home.png");
              background-size: 90%;
              background-position: center;
            }
          }
          .title_button:hover {
            cursor: pointer;
            .title_img {
              background-image: url("../assets/icon/homeblue.png");
            }
          }
        }
      }
      .info {
        text-align: left;
        img {
          width: 20px;
          vertical-align: middle;
        }
      }
      .content {
        text-align: left;
      }
      .tag {
        text-align: left;
        border-bottom: 2px #ddd solid;
        padding-bottom: 20px;
        span {
          margin: 0px 4px 2px 0px;
          padding: 2px 5px 2px 5px;
          background-color: rgb(182, 248, 182);
          border-radius: 20px;
        }
        span:hover {
          background-color: rgb(125, 255, 125);
        }
      }
      .updown {
        display: flex;
        justify-content: space-between;
        p:nth-child(2):hover {
          color: blue;
          cursor: pointer;
        }
        p:nth-child(1) {
          text-align: left;
        }
      }
    }
  }
  .right {
    width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    .right_1 {
      padding: 10px;
      background-color: #fff;
      width: 80%;
      height: 200px;
      border: #ddd solid 1px;
      border-radius: 10px;
    }
    .right_2 {
      padding: 10px;
      background-color: #fff;
      border-radius: 10px;
      width: 80%;
      border: #ddd solid 1px;
    }
    .right_3 {
      padding: 10px;
      background-color: #fff;
      border-radius: 10px;
      width: 80%;
      border: #ddd solid 1px;
    }
  }
}
</style>